home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / ButtonPanel.java < prev    next >
Text File  |  1998-06-30  |  10KB  |  289 lines

  1. /*
  2.  * @(#)ButtonPanel.java    1.6 98/01/31
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.border.*;
  23. import com.sun.java.swing.event.*;
  24. import com.sun.java.swing.text.*;
  25.  
  26. import java.awt.*;
  27. import java.awt.event.*;
  28. import java.util.*;
  29.  
  30.  
  31. /**
  32.  * Buttons!
  33.  *
  34.  * @version 1.6 01/31/98
  35.  * @author Jeff Dinkins
  36.  */
  37. public class ButtonPanel extends JPanel 
  38. {
  39.  
  40.     // The Frame
  41.     SwingSet swing;
  42.  
  43.     ImageIcon left = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/left.gif","fancy green arrow pointing left");
  44.     ImageIcon leftDown = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/leftDown.gif","fancy yellow arrow pointing left");
  45.     ImageIcon leftRollover = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/leftRollover.gif","fancy purple arrow pointing left");
  46.     ImageIcon right = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/right.gif","fancy green arrow pointing right");
  47.     ImageIcon rightDown = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/rightDown.gif","fancy yellow arrow pointing right");
  48.     ImageIcon rightRollover = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/rightRollover.gif","fancy purple arrow pointing right");
  49.  
  50.     public ButtonPanel(SwingSet swing) {
  51.     this.swing = swing;
  52.  
  53.     setBorder(swing.emptyBorder5);
  54.     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  55.  
  56.     // *************** buttons ****************
  57.     // text buttons
  58.     JPanel textButtons = SwingSet.createHorizontalPanel(false);
  59.     textButtons.setAlignmentX(LEFT_ALIGNMENT);
  60.     Border buttonBorder = new TitledBorder(null, "Text Buttons", 
  61.                            TitledBorder.LEFT, TitledBorder.TOP,
  62.                            swing.boldFont);
  63.  
  64.     Border emptyBorder = new EmptyBorder(5,5,5,5);
  65.     Border compoundBorder = new CompoundBorder( buttonBorder, emptyBorder);
  66.  
  67.     textButtons.setBorder(compoundBorder);
  68.  
  69.     JButton button;
  70.     button = new JButton("One");
  71.     button.setToolTipText("This is a Button with Text");
  72.         button.setMnemonic('o');
  73.     swing.buttons.addElement(button);
  74.     textButtons.add(button);
  75.     textButtons.add(Box.createRigidArea(swing.hpad10));
  76.     
  77.     button = new JButton("Two");
  78.     button.setToolTipText("This is a Button with Text");
  79.         button.setMnemonic('t');
  80.     swing.buttons.addElement(button);
  81.     textButtons.add(button);
  82.     textButtons.add(Box.createRigidArea(swing.hpad10));
  83.  
  84.     button = new JButton("Three");
  85.     button.setToolTipText("This is a Button with Text");
  86.         button.setMnemonic('h');
  87.     swing.buttons.addElement(button);
  88.     textButtons.add(button);
  89.  
  90.  
  91.     // image buttons
  92.     JPanel imageButtons = swing.createHorizontalPanel(false);
  93.     imageButtons.setAlignmentX(LEFT_ALIGNMENT);
  94.  
  95.     buttonBorder = new TitledBorder(null, "Image Buttons", 
  96.                            TitledBorder.LEFT, TitledBorder.TOP,
  97.                            swing.boldFont);
  98.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  99.     imageButtons.setBorder(compoundBorder);
  100.  
  101.     // 1 image
  102.     button = new JButton(swing.upButton);
  103.     button.setToolTipText("This is a Button with a Icon");
  104.     button.getAccessibleContext().setAccessibleName("Right");
  105.     // button.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);
  106.     swing.buttons.addElement(button);
  107.     imageButtons.add(button);
  108.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  109.     
  110.     // 2 images
  111.     button = new JButton(swing.upButton);
  112.     button.setToolTipText("This is a Button with a Icon and a PressedIcon");
  113.     button.getAccessibleContext().setAccessibleName("Right");
  114.     swing.buttons.addElement(button);
  115.     button.setPressedIcon(swing.downButton);
  116.     imageButtons.add(button);
  117.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  118.  
  119.     // 3 images
  120.     button = new JButton(swing.upButton);
  121.     button.setToolTipText("This is a Button with a Icon, PressedIcon, and DisabledIcon");
  122.     button.getAccessibleContext().setAccessibleName("Right");
  123.     button.setPressedIcon(swing.downButton);
  124.     button.setDisabledIcon(swing.disabledButton);
  125.     swing.buttons.addElement(button);
  126.     imageButtons.add(button);
  127.  
  128.     // text&image buttons
  129.     JPanel tiButtons = swing.createHorizontalPanel(false);
  130.     tiButtons.setAlignmentX(LEFT_ALIGNMENT);
  131.     buttonBorder = new TitledBorder(null, "Rollover Image Buttons", 
  132.                            TitledBorder.LEFT, TitledBorder.TOP,
  133.                            swing.boldFont);
  134.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  135.     tiButtons.setBorder(compoundBorder);
  136.  
  137.     button = new JButton("Left", left);
  138.     button.setPressedIcon(leftDown);
  139.     button.setRolloverIcon(leftRollover);
  140.     button.setRolloverEnabled(true);
  141.     button.setToolTipText("This is a Button with a RolloverIcon");
  142.     swing.buttons.addElement(button);
  143.     tiButtons.add(button);
  144.     tiButtons.add(Box.createRigidArea(swing.hpad10));
  145.  
  146.     button = new JButton("Right", right);
  147.     button.setPressedIcon(rightDown);
  148.     button.setRolloverIcon(rightRollover);
  149.     button.setRolloverEnabled(true);
  150.     button.setToolTipText("This is a Button with a Rollover Icon");
  151.     swing.buttons.addElement(button);
  152.     tiButtons.add(button);
  153.     tiButtons.add(Box.createHorizontalBox());
  154.  
  155.     // Add button panels to buttonPanel
  156.     JPanel buttonPanel = swing.createVerticalPanel(true);
  157.     buttonPanel.setAlignmentX(LEFT_ALIGNMENT);
  158.     buttonPanel.setAlignmentY(TOP_ALIGNMENT);
  159.  
  160.  
  161.     buttonPanel.add(textButtons);
  162.  
  163.     buttonPanel.add(Box.createVerticalStrut(10));
  164.  
  165.  
  166.     buttonPanel.add(imageButtons);
  167.  
  168.     buttonPanel.add(Box.createVerticalStrut(10));
  169.  
  170.     buttonPanel.add(tiButtons);
  171.     buttonPanel.add(tiButtons);
  172.     buttonPanel.add(Box.createGlue());
  173.  
  174.  
  175.     // *************** Create the button controls ****************
  176.     JPanel controls = new JPanel() {
  177.         public Dimension getMaximumSize() {
  178.         return new Dimension(300, super.getMaximumSize().height);
  179.         }
  180.     };
  181.     controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS));
  182.     controls.setAlignmentY(TOP_ALIGNMENT);
  183.     controls.setAlignmentX(LEFT_ALIGNMENT);
  184.  
  185.     JPanel buttonControls = swing.createHorizontalPanel(true);
  186.     buttonControls.setAlignmentY(TOP_ALIGNMENT);
  187.     buttonControls.setAlignmentX(LEFT_ALIGNMENT);
  188.  
  189.     JPanel leftColumn = swing.createVerticalPanel(false);
  190.     leftColumn.setAlignmentX(LEFT_ALIGNMENT);
  191.     leftColumn.setAlignmentY(TOP_ALIGNMENT);
  192.  
  193.     JPanel rightColumn = swing.createVerticalPanel(false);
  194.     rightColumn.setAlignmentX(LEFT_ALIGNMENT);
  195.     rightColumn.setAlignmentY(TOP_ALIGNMENT);
  196.  
  197.     buttonControls.add(leftColumn);
  198.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  199.     buttonControls.add(rightColumn);
  200.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  201.  
  202.     controls.add(buttonControls);
  203.  
  204.        
  205.     // Display Options
  206.     JLabel l = new JLabel("Display Options:");
  207.     leftColumn.add(l);
  208.     l.setFont(swing.boldFont);
  209.  
  210.      JCheckBox bordered = new JCheckBox("Paint Border");
  211.     bordered.setToolTipText("Click here to turn border painting on or off.");
  212.         bordered.setMnemonic('b');
  213.      bordered.setSelected(true);
  214.      bordered.addItemListener(swing.buttonDisplayListener);
  215.      leftColumn.add(bordered);
  216.  
  217.      JCheckBox focused = new JCheckBox("Paint Focus");
  218.     focused.setToolTipText("Click here to turn focus painting on or off.");
  219.         focused.setMnemonic('f');
  220.      focused.setSelected(true);
  221.      focused.addItemListener(swing.buttonDisplayListener);
  222.      leftColumn.add(focused);
  223.  
  224.     JCheckBox enabled = new JCheckBox("Enabled");
  225.     enabled.setToolTipText("Click here to enable or disable the buttons.");
  226.     enabled.setSelected(true);
  227.         enabled.setMnemonic('e');
  228.     enabled.addItemListener(swing.buttonDisplayListener);
  229.     leftColumn.add(enabled);
  230.  
  231.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  232.     
  233.     l = new JLabel("Pad Amount:");
  234.     leftColumn.add(l);
  235.     l.setFont(swing.boldFont);
  236.     
  237.     ButtonGroup group = new ButtonGroup();
  238.     JRadioButton defaultPad = new JRadioButton("Default");
  239.     defaultPad.setToolTipText("Uses the default padding between the border and label.");
  240.         defaultPad.setMnemonic('d');
  241.     group.add(defaultPad);
  242.     defaultPad.setSelected(true);
  243.      defaultPad.addItemListener(swing.buttonPadListener);
  244.     leftColumn.add(defaultPad);
  245.  
  246.     JRadioButton zeroPad = new JRadioButton("0");
  247.     zeroPad.setToolTipText("Uses no padding between the border and label.");
  248.         zeroPad.setMnemonic('0');
  249.     group.add(zeroPad);
  250.      zeroPad.addItemListener(swing.buttonPadListener);
  251.     leftColumn.add(zeroPad);
  252.  
  253.     JRadioButton tenPad = new JRadioButton("10");
  254.         tenPad.setMnemonic('1');
  255.     tenPad.setToolTipText("Uses a 10 pixel pad between the border and label.");
  256.     group.add(tenPad);
  257.      tenPad.addItemListener(swing.buttonPadListener);
  258.     leftColumn.add(tenPad);
  259.  
  260.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  261.  
  262.  
  263.     // *************** Create the layout controls ****************
  264.     // Create Text Position and Alignment Layout controls
  265.     JPanel textPosition = DirectionButton.createDirectionPanel(true, "E", swing.textPositionListener);
  266.     JPanel labelAlignment = DirectionButton.createDirectionPanel(true, "C", swing.labelAlignmentListener);
  267.  
  268.     l = new JLabel("Text Position:");
  269.     rightColumn.add(l);
  270.     l.setFont(swing.boldFont);
  271.      rightColumn.add(textPosition);
  272.  
  273.      rightColumn.add(Box.createRigidArea(swing.vpad20));
  274.  
  275.     l = new JLabel("Content Alignment:");
  276.     rightColumn.add(l);
  277.     l.setFont(swing.boldFont);
  278.      rightColumn.add(labelAlignment);
  279.  
  280.      rightColumn.add(Box.createGlue());
  281.  
  282.     add(buttonPanel);
  283.     add(Box.createRigidArea(swing.hpad10));
  284.      add(controls);
  285.     }
  286.  
  287.     
  288. }
  289.